<table id="dg-admin" style="height:100%;width: 100%;">
	<thead>
		<tr>
			<th data-options="field:'ck',checkbox:true"></th>
			<th data-options="field:'itemid'">Item ID</th>
	        <th data-options="field:'productid',width:'100'">Product</th>
	        <th data-options="field:'listprice',align:'right'">List Price</th>
	        <th data-options="field:'unitcost',align:'right'">Unit Cost</th>
	        <th data-options="field:'attr1'">Attribute</th>
			<th data-options="field:'status',align:'center'">Status</th>
		</tr>
	</thead>
</table>

<div id="tb-admin">
	<table cellpadding="0" cellspacing="0" style="width:100%">
		<tr class="clearfix">
			<td class="luck-tool-button luck-left">
				<a href="#" class="easyui-linkbutton button-blue" plain="true" onclick="admin_tool.add();"><i class="fa fa-plus fa-lg"></i> 添加</a>
				<a href="#" class="easyui-linkbutton button-teal" plain="true" onclick="admin_tool.edit();"><i class="fa fa-edit fa-lg"></i> 修改</a>
				<a href="#" class="easyui-linkbutton button-red" plain="true" onclick="admin_tool.edit();"><i class="fa fa-close fa-lg"></i> 删除</a>
			</td>
			<td class="luck-tool-button luck-left">
                <div class="datagrid-btn-separator"></div>
            </td>
			<td class="luck-tool-button luck-left">
				<a href="#" class="easyui-linkbutton button-black" plain="true" onclick="admin_tool.refresh();"><i class="fa fa-refresh fa-lg"></i> 刷新</a>
            </td>
			<td class="luck-tool-button luck-text-right luck-right">
				标题: <input class="easyui-textbox" name="title" style="width:200px">
				<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="admin_tool.search();">Search</a>
			</td>
		</tr>
	</table>
</div>

<div id="edit-admin"></div>

<script>
var dg=$('#dg-admin');
$(function(){
	dg.datagrid({
		url:'json/datagrid_data1.json',
		method:'get',
		idField:'itemid',
		nowrap:'false',
		fitColumns:true,
		rownumbers:true,
		sortName:'itemid',	//选择字段排序
		sortOrder:'desc',	//默认排序的方式 asc/desc
		pagination:true,	//开启分页
		pageSize:20,	//默认分页数
		pageList:[10,20,50,100],	//分页模式
		selectOnCheck:true,
		checkOnSelect:true,	//点击行选中
		singleSelect:false,	//多选
		loadMsg:'加载中...',
		striped:true,	//添加斑马线
		toolbar: '#tb-admin', 
	});
});

var admin_tool={
	add:function(){
		$('#add-dialog').dialog({
		    title: 'Add',    
		    width: 500,    
		    height:400,    
		    closed: false,    
		    cache: false,
		    cls:'theme-panel-deepblue luck-dialog-buttons',
		    modal: true,
		    href:'template/admin/add.html',
		    buttons:[{
		    	cls:'easyui-linkbutton button-blue',
		    	iconCls:'fa fa-check fa-lg',
				text:'保存',
				handler:function(){
					admin_tool.add_save();
				}
			},{
				iconCls:'fa fa-close fa-lg',
				text:'关闭',
				handler:function(){
					luck.closeDialog();
				}
			}],
		});
		//清除关闭数据没清空问题
		$("#form-add").form('clear');
	},
	refresh:function(){
		luck.refresh();
	},
	add_save:function(){
		$("#form-add").form('submit',{
			url:"1.php",
			onSubmit:function(){
				var isValid = $(this).form('validate');
				return isValid;
			},
			success:function(data){
				console.log(data);
				//$.messager.alert('Info', '1', 'info');
			}
		})
	},
	search:function(){
		dg.datagrid('load',{
			itemid: $('input[name=title]').val()
		});
	}
}
</script>